package cn.ai.shoes.client.controller;

import cn.ai.shoes.client.service.ComfyuiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 文件查看控制器
 */
@RestController
@RequestMapping("/file")
@Tag(name = "文件查看", description = "文件查看")
public class FileViewController {

    @Resource
    private ComfyuiService comfyuiService;

    /**
     * 查看文件
     * @param filename 文件名
     * @param type 类型
     * @param subfolder 子文件夹
     * @return 文件内容
     */
    @GetMapping("/view")
    @Operation(summary = "查看文件", description = "查看文件")
    @CrossOrigin(origins = "${cors.allowed.origins}")
    public ResponseEntity<byte[]> viewFile(
            @RequestParam("serverId") String serverId,
            @RequestParam("filename") String filename,
            @RequestParam("type") String type,
            @RequestParam(value = "subfolder", required = false) String subfolder) {
        return comfyuiService.getView(serverId,filename, type, subfolder);
    }
}
